package com.coc.controller;

import com.coc.pojo.Dept;
import com.coc.service.DeptService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping("/getById")
    @HystrixCommand(fallbackMethod = "hytrixGetById")
    public Dept getById(@RequestParam Integer deptNo){
        Dept dept = deptService.selectById(deptNo);
        if (dept==null){
            throw new RuntimeException("运行时出错：deptNo"+deptNo+",不存在~");
        }
        return dept;
    }

    public Dept hytrixGetById(Integer deptNo){
        return new Dept()
                .setDeptNo(deptNo)
                .setName("不存在，找不到编号为："+deptNo+"的用户")
                .setDbSource("没有这个数据库或数据库没有这个信息");
    }



}
